package com.wgy.designmode.structure.bridge;

import com.wgy.designmode.structure.bridge.color.BlueColor;
import com.wgy.designmode.structure.bridge.color.RedColor;
import com.wgy.designmode.structure.bridge.draw.DrawingApi;
import com.wgy.designmode.structure.bridge.draw.RedDrawingAPI;
import com.wgy.designmode.structure.bridge.phone.HuaWeiPhone;
import com.wgy.designmode.structure.bridge.phone.Phone;
import com.wgy.designmode.structure.bridge.phone.XiaoMiPhone;
import com.wgy.designmode.structure.bridge.shape.Circle;
import com.wgy.designmode.structure.bridge.shape.Rectangle;
import com.wgy.designmode.structure.bridge.shape.Shape;

/**
 * 桥接模式：把两个独立变化的维度抽取出来，使其可以自由扩展
 * 示例1：手机品牌和手机颜色
 * 示例2: 图形绘制系统：形状（抽象）：圆形、矩形   绘制颜色（实现）：红、蓝   抽象部分和实现部分分离，
 * 这样就可以让抽象部分和实现部分独立扩展，而不会相互影响
 */
public class BridgePatternDemo {


    public static void main(String[] args) {

        // 示例1
        // phone();
        // 示例2
        shape();
    }

    private static void shape() {
        DrawingApi redDrawingApi = new RedDrawingAPI();
        Shape circle = new Circle(redDrawingApi, 1, 1, 1);
        circle.draw();

        Shape rectangle = new Rectangle(redDrawingApi, 2, 2, 2);
        rectangle.draw();
    }

    private static void phone() {
        RedColor redColor = new RedColor();
        Phone huaWeiPhone = new HuaWeiPhone(redColor);
        huaWeiPhone.call();

        Phone xiaoMiPhone = new XiaoMiPhone(redColor);
        xiaoMiPhone.call();

        // 市场再出现一个蓝色，只需要扩展一个BlueColor即可
        BlueColor blueColor = new BlueColor();
        huaWeiPhone.setColor(blueColor);
        huaWeiPhone.call();
    }
}

